﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatabaseManager.Utilities
{
    public class StringHelper
    {
        #region 驼峰转换工具函数

        /// <summary>
        /// 转换为 PascalCase（首字母大写），适合类名
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string ToPascalCase(string input)
        {
            if (string.IsNullOrEmpty(input)) return input;

            string[] parts = input.Split(new char[] { '_', '-' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i].Length > 0)
                    parts[i] = char.ToUpper(parts[i][0]) + parts[i].Substring(1).ToLower();
            }
            return string.Join("", parts);
        }

        /// <summary>
        /// 转换为 CamelCase（默认首字母大写），适合属性名
        /// </summary>
        /// <param name="input"></param>
        /// <param name="isUpper"></param>
        /// <returns></returns>
        public static string ToCamelCase(string input, bool isUpper = true)
        {
            string pascal = ToPascalCase(input);
            if (string.IsNullOrEmpty(pascal)) return pascal;

            return isUpper ?
                char.ToUpper(pascal[0]) + pascal.Substring(1) :
                char.ToLower(pascal[0]) + pascal.Substring(1);
        }

        #endregion
    }
}
